# -*- coding: utf-8 -*-

import urllib.request
import urllib.parse

# 菜鸟教程搜索页面
url = "https://www.runoob.com/?s="
keyword = "Python 教程"
# 对请求进行编码
key_code = urllib.request.quote(keyword)
url_all = url + key_code

# 头部信息
header = {
    'User-Agent':'Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}

request = urllib.request.Request(url_all,headers=header)
reponse = urllib.request.urlopen(request).read()

# 将文件写入到当前目录中
fh = open("./urllib_test_runoob_search.html", "wb")
fh.write(reponse)
fh.close()